/**
  ******************************************************************************
  * @file    Libraries/Device/TS32Fx/TS32Fx_LL_Driver/inc/ts32fx_ll_opam.h
  * @author  TOPSYS Application Team
  * @version V1.0.0
  * @date    02-11-2018
  * @brief   This file contains all the opam LL firmware functions.
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; COPYRIGHT 2018 TOPSYS</center></h2>
  *
  *
  *
  ******************************************************************************
  */ 
  
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __TS32FX_LL_OPAM_H
#define __TS32FX_LL_OPAM_H

#ifdef __cplusplus
 extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "ts32fx.h"
     
/** @addtogroup TS32Fx_StdPeriph_Driver TS32Fx Driver
  * @{
  */
     
/** @addtogroup opam_interface_gr OPAM Driver
  * @ingroup  TS32Fx_StdPeriph_Driver
  * @{
  */ 

/** @addtogroup OPAM_LL_Driver OPAM LL Driver
  * @ingroup  opam_interface_gr
  * @brief Mainly the driver part of the OPAM module, which includes \b OPAM \b Register 
  * \b Constants, \b OPAM \b Exported \b Constants, \b OPAM \b Exported \b Struct, \b OPAM
  * \b Data \b transfers \b functions, \b OPAM \b Initialization \b and \b OPAM \b Configuration 
  * \b And \b Interrupt \b Handle \b function.
  * @{
  */

/* Exported types ------------------------------------------------------------*/

/* Exported constants --------------------------------------------------------*/

/** @defgroup OPAM_LL_Register_Constants OPAM LL Register Constants
  * @ingroup  OPAM_LL_Driver
  * @brief    OPAM LL register constant table definition
  *
  *
@verbatim   
  ===============================================================================
                                Register Constants
  ===============================================================================  
  
    Register Constants mainly encapsulates each bit in each group in the OPAM 
    register. In the process of configuration, the macro definition can be directly 
    called to configure the OPAM register, mainly for convenience. Understand the 
    configuration of the OPAM.
    
@endverbatim
  *
  * @{
  */

/***** OPMA CON(OPMA Config Register) *****/
/*! RW, Operational amplifier lock(operate once only)  
 * 0: unlock  
 * 1: lock(AMP_CON)  
 */
#define LL_OPAM_CON_LOCK_EN                       (1UL << 31)

/*! RO, Operational amplifier output(operate once only)
 */
#define LL_OPAM_CON_TRDOUT_GET(n)                 ((n >> 30) & 0x01)

/*! RW, Adaptive calibration configuration
 */
#define LL_OPAM_CON_TRIMS_SET(n)                  ((n & 0xFF) << 8)

/*! RW, Adaptive calibration enable
 */
#define LL_OPAM_CON_TRIM_EN                       (1UL << 7)

/*! RW, OPA low power enable
 */
#define LL_OPAM_CON_LOWP_EN                       (1UL << 5)

/*! RW, OPA enable signal, high level effective
 */
#define LL_OPAM_CON_EN                            (1UL << 4)

/*! RW, Positive polarity input selection  
 * 00 = PA0  
 * 01 = PC0  
 * 10 = PC1  
 * 11 = PC5  
 */
#define LL_OPAM_CON_BINX_SEL(n)                   ((n & 0x03) << 2)

/*! RW, Positive polarity input selection  
 * 00 = reserved  
 * 01 = PA2  
 * 10 = PA1  
 * 11 = PC4  
 */
#define LL_OPAM_CON_AINX_SEL(n)                   ((n & 0x03) << 0)

/**
  * @}
  */

/** @defgroup OPAM_LL_Exported_Constants OPAM LL Exported Constants
  * @ingroup  OPAM_LL_Driver
  * @brief    OPAM LL external constant definition
  *
@verbatim   
  ===============================================================================
                                Exported Constants
  ===============================================================================  
  
    Exported Constants mainly restricts the partial configuration of the abstraction 
    layer by using the form of enumeration to facilitate the use and understanding of 
    the module configuration. For the specific enumeration meaning, please refer to 
    the annotation of each module.

@endverbatim
  *
  * @{
  */
  
/***** DRIVER API *****/



/***** LL API *****/
/**
  * @brief Operational amplifier positive polarity selection mode enum type, consistent with the spec definition.
  */
typedef enum {
    /*! Positive input select PA2
     */
    LL_OPAM_AINX_SEL_PA2                              = 1,
    /*! Positive input select PA1
     */
    LL_OPAM_AINX_SEL_PA1                              = 2,
    /*! Positive input select PC4
     */
    LL_OPAM_AINX_SEL_PC4                              = 3,
    
} TYPE_ENUM_LL_OPAM_AINX_SEL;

/**
  * @brief  Operational amplifier negative polarity selection mode enum type, consistent with the spec definition.
  */
typedef enum {
    /*! Negative input select PA0
     */
    LL_OPAM_BINX_SEL_PA0                              = 0,
    /*! Negative input select PC0
     */
    LL_OPAM_BINX_SEL_PC0                              = 1,
    /*! Negative input select PC1
     */
    LL_OPAM_BINX_SEL_PC1                              = 2,
    /*! Negative input select PC2
     */
    LL_OPAM_BINX_SEL_PC5                              = 3,
    
} TYPE_ENUM_LL_OPAM_BINX_SEL;


 
/***** LL API AND DRIVER API *****/



/**
  * @}
  */

/** @defgroup OPAM_LL_Exported_Struct OPAM LL Exported Struct
  * @ingroup  OPAM_LL_Driver
  * @brief    OPAM LL external configuration structure definition
  *
@verbatim   
  ===============================================================================
                                Exported Struct
  ===============================================================================  

    Exported Struct mainly extracts the OPAM registers from the API, and abstracts 
    the structure. As long as it implements the low coupling between the registers 
    and the registers, the user only needs to configure the structure of the abstraction 
    layer and call hal_opam_init. Function, you can configure the OPAM module without 
    involving the configuration of the collective register.

@endverbatim
  *
  * @{
  */

/**
  * @brief OPAM low layer config struct
  */
typedef struct __ll_opam_init {
    /*! operational amplifier positive input selection
     */
    TYPE_ENUM_LL_OPAM_AINX_SEL           ainx_sel;
    /*! operational amplifier negative input selection
     */
    TYPE_ENUM_LL_OPAM_BINX_SEL           binx_sel;
    /*! operational amplifier adaptive calibration enable enable or disable  
     */
    FunctionalState                      trim_en;
    /*! operational amplifier low power enable or disable
     */
    FunctionalState                      low_power_en;
    /*! operational amplifier enable or disable
     */
    FunctionalState                      opam_en;
    /*! operational amplifier adaptive calibration value
     */
    u8                                   trim_value;
} TYPE_LL_OPAM_INIT;


/**
  * @}
  */

/** @defgroup OPAM_LL_Interrupt OPAM LL Interrupt Handle function
  * @brief   OPAM LL Interrupt Handle function
  *
@verbatim   
  ===============================================================================
                        Interrupt Handle function
  ===============================================================================  

    This subsection provides a set of functions allowing to manage the OPAM  
    Interrupt Handle function.

    how to use?

    The OPAM interrupt handler uses a callback method that reserves the interface 
    to the user in the form of a callback function. The client needs to initialize 
    the callback function when initializing the OPAM in order for the interrupt to 
    be processed normally. 
   
@endverbatim
  *
  * @{
  */



/**
  * @}
  */
  
/** @defgroup OPAM_LL_Inti_Cfg OPAM LL Initialization And Configuration
  * @brief    OPAM LL Initialization And Configuration
  *
@verbatim   
  ===============================================================================
                        Initialization And Configuration
  ===============================================================================  

    This subsection provides a set of functions allowing to manage the OPAM data 
    Initialization and Configuration.
    
    how to use?

@endverbatim
  *
  * @{
  */

  /**
  * @brief  opam init
  * @param  p_opam : pointer to the hardware OPAM_TypeDef
  * @param  p_init: pointer to the init stuct TYPE_LL_OPAM_INIT
  * @retval None
  */
void ll_opam_init(OPAM_TypeDef *p_opam, TYPE_LL_OPAM_INIT *p_init);


/**
  * @}
  */
  
/** @defgroup OPAM_LL_Data_Transfers OPAM LL Data transfers functions
  * @brief    OPAM LL Data transfers functions 
  *
@verbatim   
  ===============================================================================
                            Data transfers functions
  ===============================================================================  

    This subsection provides a set of functions allowing to manage the OPAM data 
    transfers and receive.
  
@endverbatim
  *
  * @{
  */

/**
  * @brief  operational amplifier enable
  * @param  p_opam : pointer to the hardware OPAM_TypeDef
  * @retval None
  */
void ll_opam_enable(OPAM_TypeDef *p_opam);

/**
  * @brief  operational amplifier disable
  * @param  p_opam : pointer to the hardware OPAM_TypeDef
  * @retval None
  */
void ll_opam_disable(OPAM_TypeDef *p_opam);

/**
  * @brief  operational amplifier enable get status
  * @param  p_opam : pointer to the hardware OPAM_TypeDef
  * @retval None
  */
#define LL_OPAM_EN_GET(p_opam)             ((p_opam)->CON & LL_OPAM_CON_EN)

/**
  * @brief  operational amplifier adaptive calibration enable
  * @param  p_opam : pointer to the hardware OPAM_TypeDef
  * @retval None
  */
void ll_opam_trim_enable(OPAM_TypeDef *p_opam);

/**
  * @brief  operational amplifier adaptive calibration disable
  * @param  p_opam : pointer to the hardware OPAM_TypeDef
  * @retval None
  */
void ll_opam_trim_disable(OPAM_TypeDef *p_opam);

/**
  * @brief  operational amplifier adaptive calibration enable get
  * @param  p_opam : pointer to the hardware OPAM_TypeDef
  * @retval result
  */
#define LL_OPAM_TRIM_EN_GET(p_opam)                ((p_opam)->CON & LL_OPAM_CON_TRIM_EN)

/**
  * @brief  operational amplifier low power enable
  * @param  p_opam : pointer to the hardware OPAM_TypeDef
  * @retval None
  */
void ll_opam_lowp_enable(OPAM_TypeDef *p_opam);

/**
  * @brief  operational amplifier low power disable
  * @param  p_opam : pointer to the hardware OPAM_TypeDef
  * @retval None
  */
void ll_opam_lowp_disable(OPAM_TypeDef *p_opam);

/**
  * @brief  operational amplifier low power enable get
  * @param  p_opam : pointer to the hardware OPAM_TypeDef
  * @retval result
  */
#define LL_OPAM_LOWP_EN_GET(p_opam)               (p_opam->CON & LL_OPAM_CON_LOWP_EN)

/**
  * @brief  operational amplifier register lock enable(only set it once)
  * @param  p_opam : pointer to the hardware OPAM_TypeDef
  * @retval None
  */
void ll_opam_lock_enable(OPAM_TypeDef *p_opam);

/**
  * @brief  operational amplifier get register lock status
  * @param  p_opam : pointer to the hardware OPAM_TypeDef
  * @retval result
  */
#define LL_OPAM_LOCK_EN_GET(p_opam)                ((p_opam)->CON & LL_OPAM_CON_LOCK_EN)


/**
  * @}
  */

/**
  * @}
  */

#ifdef __cplusplus
}
#endif

/**
  * @}
  */

/**
  * @}
  */

#endif //__TS32FX_LL_OPAM_H

/*************************** (C) COPYRIGHT 2018 TOPSYS ***** END OF FILE *****/
